/**
 * Copyright © 2021-2025 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.invoice.invoice.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeeplus.invoice.invoice.service.dto.YxfpInvoiceDTO;
import com.jeeplus.invoice.invoice.domain.YxfpInvoice;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 *  发票管理MAPPER接口
 * @author 张如利
 * @version 2022-02-16
 */
public interface YxfpInvoiceMapper extends BaseMapper<YxfpInvoice> {

    /**
     * 根据id获取 发票管理
     * @param id
     * @return
     */
    YxfpInvoiceDTO findById(String id);

    /**
     * 获取 发票管理列表
     *
     * @param queryWrapper
     * @return
     */
    IPage <YxfpInvoiceDTO> findList(Page <YxfpInvoiceDTO> page, @Param(Constants.WRAPPER) QueryWrapper queryWrapper);

    /**
     * 根据客户ID查询客户所开的发票列表数据
     * @param customerId
     * @return
     */
    @Select("select * from yxfp_invoice where customer_id = #{0} order by update_date desc")
    List<YxfpInvoiceDTO> getInvoiceListByCustomerId(String customerId);

    /**
     * 根据商户ID查询客户所开的发票列表数据
     * @param merchantId
     * @return
     */
    @Select("select * from yxfp_invoice where merchant_id = #{0} order by update_date desc")
    List<YxfpInvoiceDTO> getInvoiceListByMerchanId(String merchantId);

    /**
     * 根据商户ID和发票状态查询发票列表数据
     * @param merchantId
     * @param state
     * @return
     */
    @Select("select * from yxfp_invoice where merchant_id = #{0} and state = #{1} order by update_date desc")
    List<YxfpInvoiceDTO> getInvoiceListByMerchantIdAndState(String merchantId,String state);

    /**
     * 根据客户ID和商户名称查询发票列表数据
     * @param customerId
     * @param merchantName
     * @return
     */
    //@Select("select a.*,b.merchant_name AS merchant.merchantName from yxfp_invoice a LEFT JOIN yxfp_merchant b on a.merchant_id = b.id where a.customer_id = #{0} and b.merchant_name like #{1} order by a.update_date desc")
    List<YxfpInvoiceDTO> getInvoiceListByCustomerIdAndMerchantName(String customerId,String merchantName);
}
